﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class FormulaireAdherent : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            dpMetier.DataSource = FonctionDAO.retournerFonction();
            dpMetier.DataBind();
        }
        
    }
    protected void btAjoutDirigeant_Click(object sender, EventArgs e)
    {
        AdherentCritere unAdherentcritere = new AdherentCritere();

        unAdherentcritere.nom = tbNom.Text;
        unAdherentcritere.prenom = tbPrenom.Text;
        unAdherentcritere.dateNaissance = Convert.ToDateTime(tbNaissance.Text);
        unAdherentcritere.adresse = tbAdresse.Text;
        unAdherentcritere.cp = tbCp.Text;
        unAdherentcritere.ville = tbVille.Text;
        unAdherentcritere.tel = tbTel.Text;
        unAdherentcritere.mail = tbMail.Text;
        String login = unAdherentcritere.prenom.Substring(0, 1) + unAdherentcritere.nom;
        unAdherentcritere.login = login;
        unAdherentcritere.motdepasse = "toto";
        unAdherentcritere.dateInscription = DateTime.Now;
        unAdherentcritere.dateDesinscription = DateTime.Parse("01/01/1753 00:00:00");

        if (uploadphoto.HasFile)
        {
            uploadphoto.PostedFile.SaveAs(@"C:\Users\AHAMADA\Documents\Visual Studio 2008\WebSites\gestionassos\Images\" + uploadphoto.FileName);

            // uploadphoto.PostedFile.SaveAs("C:\\Documents and Settings\\sahamada\\Mes documents\\Visual Studio 2008\\WebSites\\gestionassos\\Images\\" + uploadphoto.FileName);
            unAdherentcritere.lienPhoto = uploadphoto.FileName;
        }
        AdherentDAO.ajouterAdherent(unAdherentcritere);
        int idDirigeant = AdherentDAO.retournerId(unAdherentcritere.login);

        DirigeantCritere unDirigeantcritere = new DirigeantCritere();
        unDirigeantcritere.id = idDirigeant;
        unDirigeantcritere.idFonction = dpMetier.SelectedIndex;
        DirigeantDAO.ajouterDirigeant(unDirigeantcritere);

        Response.Redirect("EspaceAdministrateur.aspx");

    }


    protected void btAjoutJoueur_Click(object sender, EventArgs e)
    {

        AdherentCritere unAdherentcritere = new AdherentCritere();

        unAdherentcritere.nom = tbNom.Text;
        unAdherentcritere.prenom = tbPrenom.Text;
        unAdherentcritere.dateNaissance = Convert.ToDateTime(tbNaissance.Text);
        unAdherentcritere.adresse = tbAdresse.Text;
        unAdherentcritere.cp = tbCp.Text;
        unAdherentcritere.ville = tbVille.Text;
        unAdherentcritere.tel = tbTel.Text;
        unAdherentcritere.mail = tbMail.Text;
        String login = unAdherentcritere.prenom.Substring(0,1) + unAdherentcritere.nom;
        unAdherentcritere.login =login;
        unAdherentcritere.motdepasse = "toto";
        unAdherentcritere.dateInscription = DateTime.Now;
        unAdherentcritere.dateDesinscription = DateTime.Parse("01/01/1753 00:00:00");
        
         if (uploadphoto.HasFile){
             uploadphoto.PostedFile.SaveAs(@"C:\Users\AHAMADA\Documents\Visual Studio 2008\WebSites\gestionassos\Images\" + uploadphoto.FileName);

            // uploadphoto.PostedFile.SaveAs("C:\\Documents and Settings\\sahamada\\Mes documents\\Visual Studio 2008\\WebSites\\gestionassos\\Images\\" + uploadphoto.FileName);
             unAdherentcritere.lienPhoto = uploadphoto.FileName;
         }
         AdherentDAO.ajouterAdherent(unAdherentcritere);
         int idjoueur =AdherentDAO.retournerId(unAdherentcritere.login);
         JoueurCritere unJoueurcritere = new JoueurCritere();

         unJoueurcritere.id = idjoueur;
         unJoueurcritere.piedJoueur = tbPied.Text;
         unJoueurcritere.poids = Convert.ToInt32(tbPoidsAdherent.Text);
         unJoueurcritere.poste = tbPoste.Text;
         unJoueurcritere.taille = Convert.ToInt32(tbTailleAdherent.Text);
         unJoueurcritere.ancienClub = tbClubAdherent.Text;
        // unJoueurcritere.numeroJoueur = tb
         JoueurDAO.ajouterJoueur(unJoueurcritere);

         Response.Redirect("EspaceAdministrateur.aspx");
        
    }
    protected void tbMail_TextChanged(object sender, EventArgs e)
    {

    }
}
